package org.openfans.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.openfans.domain.Facade;
import org.openfans.domain.UseStatus;
import org.openfans.util.ThreadFans;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;

public class JudgeRootTagController extends AbstractController {
	private Facade facade = null;

	public void setFacade(Facade facade) {
		this.facade = facade;
	}

	protected ModelAndView handleRequestInternal(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		ThreadFans.authorize();
		String tagId = request.getParameter("id");
		String statusStr = request.getParameter("status");
		int status = 0;
		if ("used".equals(statusStr)) {
			status = UseStatus.USED;
		} else if ("using".equals(statusStr)) {
			status = UseStatus.USING;
		} else if ("prepare".equals(statusStr)) {
			status = UseStatus.PREPARE;
		}

		facade.saveJudgeRootTag(tagId, status);

		return new ModelAndView("redirect:viewTag.html?id=" + tagId);
	}

	
}
